package Ctr;

import Model.*;

public class ForestOwnerCtr {

    private ForestCollection forestCollection;
    private OwnerCollection ownerCollection;

    public ForestOwnerCtr() {
    }

    public ForestOwnerCtr(ForestCollection forestCollection, OwnerCollection ownerCollection) {
        forestCollection = forestCollection.getInstance();
        ownerCollection = ownerCollection.getInstance();
    }

    //Add an owner
    public void addOwner(String ownerName, String ownerAddress, int ownerPhone){
        Owner owner = new Owner(ownerName, ownerAddress, ownerPhone);
        ownerCollection.addOwner(owner);
    }

    //Add a forest
    public void addForest(String forestName, String forestLocation, int forestSize, int forestAge, Owner forestOwner){
        Forest forest = new Forest(forestName, forestLocation, forestSize, forestAge);
        forestCollection.addForest(forest);
    }

    //Owner search
    public Owner ownerSearch(String name){
        if (ownerCollection.findOwner(name) == null){
            return null;
        }
        else { return ownerCollection.findOwner(name); }
    }

    //Forest search
    public Forest forestSearch(String name){
        if (forestCollection.findForest(name) == null){
            return null;
        }
        else { return forestCollection.findForest(name); }
    }

    //Add and owner to a forest
    public void addForestOwner(String ownerName, String forestName){
        Forest forest = forestSearch(forestName);
        forest.setForestOwner(ownerSearch(ownerName));
    }

    //Add a tree object to a forest
    public void addForestTrees(String forestName, String treeSort, int treeLifespan, int treeSize, double treeCostPrm2, double treeEarnPrm2){
        Tree tree = new Tree(treeSort, treeLifespan, treeSize, treeCostPrm2, treeEarnPrm2);
        Forest forest = forestSearch(forestName);
        forest.setTree(tree);
    }
}
